<template>
 <view class="main">
	 <view class="logo">
	 	 <view class="ilist" @click="myitem">
	 	    <image src="https://ppp.new.zeroitem.cn/ppp/menu.png" style="width:64rpx;height:64rpx"></image>
	 	 </view>
	 	 <image src="https://ppp.new.zeroitem.cn/ppp/logo.png" class="imglog"></image>   
	 </view>
	<view class="main1">
		<view class="main2">
		  <view class="p2-1">
	        <view class="face1">
			 <image :src="psdetail.avatar" class="pimg1"></image>
			 </view>
			<view class="p2-c">
			  <view class="p2-c-1" @click="showtc2()">{{psdetail.xm}}</view>
			  <view class="p2-c-2">
				<view class="pmm1">
					<image src="https://ppp.new.zeroitem.cn/ppp/cert.png" class="pimg66"></image>
					实名认证
				 </view>
				<view class="pmm2" v-if="psdetail.level==3"> 达人影像拍手</view>
				<view class="pmm2" v-if="psdetail.level==2"> 普通拍手</view>
				<view class="pmm2" v-if="psdetail.level==1"> 实习拍手</view>
			  </view>
			</view> 
			<view class="simglist">
			<image :src="item" v-for="(item,index) in psdetail.sarr" class="pimg2"></image>
			</view>
		  </view>
		  <view class="p2-2" @click="showtc1()">
			 <view class="p2-2-1">
			   {{psdetail.desc}}
			 </view>  
		  </view>
		  <view class="p3-3" @click="dingwei"> 
		   {{psdetail.bd.result.addressComponent.city}}.{{psdetail.bd.result.addressComponent.district}}
		   </view>
		</view>
	     <view class="part2">
		   <view class="pt2-1" @click="jumpp()">
			   <view class="ptx-1">{{psdetail.order_num}}</view>
			   <view class="ptx-2">订单</view>
		   </view>
		   <view class="ptline"></view>
		   <view class="pt2-2">
			   <view class="ptx-1">{{psdetail.yxnum}}</view>
			   <view class="ptx-2">优选</view>
		   </view>
		   <view class="ptline"></view>
		   <view class="pt2-3">
			   <view class="ptx-1">{{psdetail.vote_num}}</view>
			   <view class="ptx-2">点赞</view>
		   </view>
		 </view>
	</view> 
	<view class="part3">
	   <view class="part3-1" :class="[{'pcur':tab == 1}]" @click="settab(1)">达人优选</view>
	   <view class="part3-2" :class="[{'pcur':tab == 2}]" @click="settab(2)">普通作品</view>
	   <image src="https://ppp.new.zeroitem.cn/ppp/add.png" class="padd" @click="padd"></image>
	</view>
	<view class="part4" v-if="tab==1"></view>	
	<view class="part4-1" v-if="tab==2"></view>
   <block v-if="tab==1">
   <view class="part5" v-for="(item,index) in yxlist" v-if="item.is_show1==1">
	  <view class="part5-1">
		 <view class="p5-1-1">{{item.zpmc}}</view>  
		 <view class="p5-1-2">
			<image src="https://ppp.new.zeroitem.cn/ppp/tool3.png?v=1" class="timg" @click="jump(item.id)"></image> 
			<image src="https://ppp.new.zeroitem.cn/ppp/tool2.png?v=2" class="timg" @click="ydelconfire(item.id,index)"></image>
			<image src="https://ppp.new.zeroitem.cn/ppp/tool1.png?v=3" class="timg" @click="psort(item.id,index)"></image>
		 </view>	 
	  </view> 
	  <video :src="item.src1" class="videoc" objectFit="cover" :id="'id'+item.id" @play="videoPlayHandle('id'+item.id)" v-if="item.play==1"></video>
	  <image :src="item.video_pic" class="videoc" v-if="item.play==0" @click="showplay(index)"></image>
   </view> 
   </block>
   <block v-if="tab==2">
   <view class="part5" v-for="(item,index) in jlist">
	  <view class="part5-1" style="justify-content: space-around;">
		 <view class="p5-1-1">{{item.pdate}} {{item.ptime}}  <view class="ddsz" @click="setorder(item.id)">[订单设置]</view></view>  
		 <view class="p5-1-2">{{item.total_price}}￥</view>	 
	  </view> 
	  <video :src="item.src1" class="videoc" objectFit="cover" :id="'oid'+item.id" @play="ovideoPlayHandle('oid'+item.id)" v-if="item.play==1"></video>
	  <image :src="item.video_pic" class="videoc" v-if="item.play==0" @click="oshowplay(index)"></image>
   </view> 
   </block>

  <view class="mask" v-if="descShow">
  	 <view class="bztc1">
  		 <view class="bzpp1">编辑简介</view>
  		 <view class="line2" style="margin-top:10rpx"></view>
  		  <textarea placeholder="请输入您要所示的内容" class="barea" v-model="psdetail.desc"></textarea>
  			<view class="line2"></view>
  			<view class="tjbtn" @click="confirmAdd1">确定</view>
  	 </view>
  </view>

  <view class="mask" v-if="xmShow">
  	 <view class="bztc1">
  		 <view class="bzpp1">修改用户名</view>
  		 <view class="line2" style="margin-top:10rpx"></view>
  		    <input type="text" placeholder="请输入需要修改的用户名" v-model="psdetail.xm" class="xminput" style="height:80rpx;!important"/>
  			<view class="line2"></view>
  			<view class="tjbtn" @click="confirmAdd2">确定</view>
  	 </view>
  </view>


  <view class="mask" v-if="setshow">
  	 <view class="bztc1">
  		 <view class="bzpp1">订单显示设置</view>
  		 <view class="line2" style="margin-top:30rpx"></view>

			<view class="chk-conclusion">
				<label class="label-title">达人优选显示状态</label>
				<radio-group @change="conclusionChange1" class="labelbox">
					<label class="radio">
						<radio value="1" :checked="drRadio==1" /> 显示
					</label>
					<label class="radio" style="margin-left: 20px;">
						<radio value="0" :checked="drRadio==0" /> 不显示
					</label>
				</radio-group>
				
			<label class="label-title">视频保密状态</label>
			<radio-group @change="conclusionChange2" class="labelbox">
				<label class="radio">
					<radio value="0" :checked="bmRadio==0" /> 展示给用户
				</label>
				<label class="radio" style="margin-left: 20px;">
					<radio value="1" :checked="bmRadio==1" /> 不展示给用户
				</label>
			</radio-group>			
				
				
			</view>
	
  			 <view class="line2" style="margin-top:30rpx"></view>
  			<view class="tjbtn" @click="confirmAdd3">确定</view>
  	 </view>
  </view>


  	   
 </view>
</template>

<script>
import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		toLogin
	} from '@/utils/login'
	
	import {
		loadingFun,
		menuJump,
		jumpurl
	} from '@/utils/tools'	
    import {
	   yxlist,psdetail,savepsaddress,delpszp,zpport,jdjl,savexm,savedesc,getOrderDetail,saveorder
	} from '@/api/ppp'	
    import {
		loadingType
	} from '@/utils/type'

	const app = getApp()	
	export default {
	    data() {
	        return {
             zt:0,
			 yxlist:[],
			 jlist:[],
			 pid:0,
			 page: 1,
			 video:null,
			 ovideo:null,
			 psdetail:[],
			 address:"",
			 latitude:"",
			 longitude:"",
			 xmShow:false,
			 descShow:false,
			 setshow:false,
			 drRadio:0,
			 bmRadio:0,
			 tab:1,
			 oid:0,
			 status: loadingType.LOADING
	        }
	    },
		onShow(){
	     
		},
		onReachBottom() {
		if(this.tab==1){
		 this.showyxlist();
		}
		if(this.tab==2){
		 this.getjdjl();	
		}
		 setTimeout(() => {
		 	uni.stopPullDownRefresh();
		 }, 1000);	
		},
		onLoad(option){
		 if(option.pid!=undefined){
		  this.pid=option.pid;
		 }
		 this.showyxlist(this.pid);
		 this.getdetail();
		},
	    methods: {
		 conclusionChange1(val){
			 this.drRadio=val.detail.value; 
			 console.log(val);
		 },
		 conclusionChange2(val){
			this.bmRadio=val.detail.value;  
		 },
		  async setorder(oid){
			 const{code,msg,data,
			 }=await getOrderDetail({id:oid}); 
			 if(code==1){
			   this.setshow=true;
			   this.drRadio=data.tj;
			   this.bmRadio=data.bm;
			   this.oid=oid;
			 }
		  },
		  showtc2(){
			this.xmShow=true;  
		  },
		  showtc1(){
		     this.descShow=true;  
		  },
		  closexmtc(){
			this.xmShow=false;   
		  },
		  myitem(){
		   jumpurl('pages/ppp/ps/menu');
		  },
          async getjdjl(){
			var that=this;
			 const data = await loadingFun(jdjl,this.page,this.jlist,this.status,{tab:-1});
			 if (!data) return
			 this.page = data.page
			 this.jlist = data.dataList
			 this.status = data.status	
          },
		 async confirmAdd1(){
		  var that=this;
		  var desc=this.psdetail.desc;
		  if(desc==''){uni.toast({icon:'none',title:'请填写简介'});return false;}
		  const{code,msg,data,
		  }= await savedesc({desc:desc});
		  if(code==1){
			this.descShow=false;  
		  }
		 },
		 async confirmAdd2(){
			var that=this;
			var xm=this.psdetail.xm;
			if(xm==''){uni.toast({icon:'none',title:'请填写姓名'});return false;}
			const{code,msg,data,
			}= await savexm({xm:xm});
			if(code==1){
			 this.xmShow=false;  
			} 
		 },
		 jumpp(){
			jumpurl("pages/ppp/ps/jjjl"); 
		 },
		 async confirmAdd3(){
		 			var that=this;
		 			var bmRadio=this.bmRadio;
					var drRadio=this.drRadio;
					var oid=this.oid;
		 			const{code,msg,data,
		 			}= await saveorder({bmRadio:bmRadio,drRadio:drRadio,oid:oid});
		 			if(code==1){
		 			 that.setshow=false;
					 uni.showToast({icon:'none',title:'设置成功'});
		 			} 
		 },
		settab(tab_id){
		 var that=this;
		 that.tab=tab_id;
		 if(tab_id==2){
		  that.page=1;
		  that.jlist=[];
		  that.status=loadingType.LOADING;
		  that.getjdjl();
		 }
		 if(tab_id==1){
		  that.page=1;
		  that.yxlist=[];
		  that.status=loadingType.LOADING;
		  that.showyxlist();
		 }
		},
		jump(zid){
		 jumpurl("pages/ppp/ps/tjyx?zid="+zid);
		},
		async psort(id,index){
		 var that=this;
		 var yxlist=that.yxlist;
		 var pnum=yxlist[index].pnum;
		 if(pnum==1){return false;}
				var index1=index-1;
				var item1=yxlist[index];
				var item2=yxlist[index1];
				const{
				 code,
				 msg,
				 data
				}= await zpport(id,item2.id);
				if(code==1){
					yxlist[index1]=item1;
					yxlist[index1].pnum=item2.pnum;
					yxlist[index]=item2;
					yxlist[index].pnum=item1.pnum;
					that.yxlist=yxlist;
				}
		},
		
		ydelconfire(id,index){
		  var that=this;
		  uni.showModal({
		      title: '删除确认',
		      content: '您确定要删除该作品吗？',
		      success: function (res) {
		          if (res.confirm) {
		           that.ydel(id,index);
		          } else if (res.cancel) {
		            
		          }
		      }
		  });	
		},
	    async ydel(id,index){
		  var that=this;
		  const{
		   code,
		   msg,
		   data
		  }= await delpszp(id);
		  if(code==1){
			uni.showToast({icon:'none',title:'删除成功'});
		    var yxlist=that.yxlist;
			yxlist[index].is_show1=0;
			that.yxlist=yxlist;
		  }  	
		},
		dingwei(){
		  var that=this;
		  uni.chooseLocation({
		  	success:(res)=> {
		  	  that.address=res.address;
		  	  that.latitude=res.latitude;
		  	  that.longitude=res.longitude;
			  that.savepsaddress1({address:res.address,lat:res.latitude,lng:res.longitude})
		  	}
		   })
		},
		async savepsaddress1(data){
		  var that=this;
		  const{
		   code,
		   msg,
		   data1
		  }= await savepsaddress(data);
		  if(code==1){
		    that.getdetail();
		  }  	
		},
		showplay(index){
			  var that=this;
			  var yxlist=that.yxlist
			  yxlist[index].play=1;
			  yxlist[index].src1=yxlist[index].video_src;
			  that.yxlist=yxlist;
			  that.videoPlayHandle('id'+yxlist[index].id);
			  
			},
		    videoPlayHandle(id) {
			let newVideo = uni.createVideoContext(id);
			console.log(newVideo);
			console.log(id);
			newVideo.id = id;
			if (!this.video) {
				this.video = newVideo;
				this.video.play();
				return
			}
			if (this.video.id !== newVideo.id) {
				newVideo.play();
				this.video.pause();
				this.video = newVideo;
			}
		},
		
		
		oshowplay(index){
			  var that=this;
			  var jlist=that.jlist
			  if(jlist[index].has_video==0){
				uni.showToast({icon:'none',title:'暂无相关视频'});
				return false;  
			  }
			  jlist[index].play=1;
			  jlist[index].src1=jlist[index].video_src;
			  that.jlist=jlist;
			  that.ovideoPlayHandle('oid'+jlist[index].id);
			  
			},
		    ovideoPlayHandle(id) {
			let newVideo = uni.createVideoContext(id);
			newVideo.id = id;
			if (!this.ovideo) {
				this.ovideo = newVideo;
				this.ovideo.play();
				return
			}
			if (this.ovideo.id !== newVideo.id) {
				newVideo.play();
				this.ovideo.pause();
				this.ovideo = newVideo;
			}
		},		
		
		
		
		
		
		
		
		  qbtn(){
			this.zt=0;
		  },
		  settype(type){
			this.zt=type; 
		  },
		  async getdetail(){
			var that=this;
			const{
			 code,
			 msg,
			 data
			}= await psdetail({});
			if(code==1){
			  that.psdetail=data;
			}	
		  },
		  
		  async showyxlist(){
			var that=this;
			 const data = await loadingFun(yxlist,this.page,this.yxlist,this.status,{pid:this.pid});
			 if (!data) return
			 this.page = data.page
			 this.yxlist = data.dataList
			 this.status = data.status	
		  },
		  padd(){
		   jumpurl('pages/ppp/ps/tjyx');
		  }
	    },
		computed: {
			...mapGetters(['isLogin']),
		}
	}
</script>

<style>
 @import "./main1.css";	
</style>
